<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #4F46E5;
            --primary-dark: #4338CA;
            --secondary: #10B981;
            --light: #F9FAFB;
            --dark: #1F2937;
            --gray: #6B7280;
            --light-gray: #E5E7EB;
            --border: #D1D5DB;
            --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            --success: #10B981;
            --warning: #F59E0B;
        }

        body {
            background: linear-gradient(135deg, #f0f7ff 0%, #f8fafc 100%);
            color: var(--dark);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        /* 头部样式 */
        header {
            background: white;
            border-radius: 16px;
            box-shadow: var(--card-shadow);
            padding: 20px 30px;
            margin-bottom: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 20px;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--primary);
        }

        .logo i {
            font-size: 1.8rem;
        }

        .header-controls {
            display: flex;
            gap: 15px;
            flex-wrap: wrap;
        }

        .class-filter {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        select {
            padding: 10px 15px;
            border-radius: 8px;
            border: 1px solid var(--border);
            background: white;
            font-size: 1rem;
            min-width: 150px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
        }

        .file-upload {
            position: relative;
            display: inline-block;
        }

        .file-upload-btn {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            background: var(--primary);
            color: white;
            padding: 10px 20px;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .file-upload-btn:hover {
            background: var(--primary-dark);
            transform: translateY(-2px);
        }

        #file-input {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }

        .stats {
            display: flex;
            gap: 15px;
            margin-top: 10px;
            flex-wrap: wrap;
        }

        .stat-card {
            background: var(--light);
            border-radius: 10px;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 180px;
        }

        .stat-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.2rem;
        }

        .stat-content {
            display: flex;
            flex-direction: column;
        }

        .stat-value {
            font-size: 1.4rem;
            font-weight: 700;
        }

        .stat-label {
            font-size: 0.9rem;
            color: var(--gray);
        }

        /* 表格区域 */
        .table-container {
            background: white;
            border-radius: 16px;
            box-shadow: var(--card-shadow);
            padding: 25px;
            overflow-x: auto;
        }

        .table-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            flex-wrap: wrap;
            gap: 15px;
        }

        .table-title {
            font-size: 1.5rem;
            font-weight: 600;
            color: var(--dark);
        }

        .search-box {
            display: flex;
            align-items: center;
            background: var(--light);
            border-radius: 8px;
            padding: 8px 15px;
            border: 1px solid var(--border);
        }

        .search-box input {
            border: none;
            background: transparent;
            padding: 5px 10px;
            font-size: 1rem;
            min-width: 200px;
        }

        .search-box input:focus {
            outline: none;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        thead {
            background: var(--light);
        }

        th {
            padding: 15px;
            text-align: left;
            font-weight: 600;
            color: var(--dark);
            border-bottom: 2px solid var(--border);
            cursor: pointer;
            position: relative;
        }

        th:hover {
            background: #f3f4f6;
        }

        th::after {
            content: "↕";
            position: absolute;
            right: 10px;
            color: var(--gray);
            font-size: 0.8rem;
        }

        td {
            padding: 15px;
            border-bottom: 1px solid var(--border);
        }

        tr:last-child td {
            border-bottom: none;
        }

        tr:hover {
            background: rgba(79, 70, 229, 0.05);
        }

        .student-id {
            font-weight: 600;
            color: var(--primary);
        }

        .class-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 500;
        }

        .class-1 {
            background: #DBEAFE;
            color: #1D4ED8;
        }

        .class-2 {
            background: #FCE7F3;
            color: #BE185D;
        }

        .class-3 {
            background: #D1FAE5;
            color: #047857;
        }

        .class-4 {
            background: #FEF3C7;
            color: #B45309;
        }

        .actions {
            display: flex;
            gap: 10px;
        }

        .action-btn {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--light);
            color: var(--gray);
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .action-btn:hover {
            background: var(--primary);
            color: white;
            transform: scale(1.1);
        }

        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: var(--gray);
        }

        .empty-state i {
            font-size: 4rem;
            color: var(--light-gray);
            margin-bottom: 20px;
        }

        .empty-state p {
            font-size: 1.2rem;
            max-width: 500px;
            margin: 0 auto;
        }

        /* 页脚 */
        footer {
            text-align: center;
            padding: 30px 0;
            color: var(--gray);
            margin-top: 40px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            header {
                flex-direction: column;
                align-items: flex-start;
            }

            .header-controls {
                width: 100%;
            }

            .class-filter,
            .file-upload {
                width: 100%;
            }

            select {
                width: 100%;
            }

            .file-upload-btn {
                width: 100%;
                justify-content: center;
            }

            .stats {
                width: 100%;
            }

            .stat-card {
                flex: 1;
                min-width: 0;
            }

            th,
            td {
                padding: 10px;
                font-size: 0.9rem;
            }
        }

        @media (max-width: 480px) {
            .table-header {
                flex-direction: column;
                align-items: flex-start;
            }

            .search-box {
                width: 100%;
            }

            .search-box input {
                width: 100%;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 头部区域 -->
        <header>
            <div class="logo">
                <i class="fas fa-user-graduate"></i>
                <span>学生管理系统</span>
            </div>

            <div class="header-controls">
                <div class="class-filter">
                    <label for="class-select"><i class="fas fa-filter"></i> 班级筛选：</label>
                    <select id="class-select">
                        <option value="all">全部班级</option>
                        <option value="1">高一(1)班</option>
                        <option value="2">高一(2)班</option>
                        <option value="3">高一(3)班</option>
                        <option value="4">高一(4)班</option>
                    </select>
                </div>

                <div class="file-upload">
                    <div class="file-upload-btn">
                        <i class="fas fa-file-upload"></i>
                        上传Excel数据
                    </div>
                    <input type="file" id="file-input" accept=".xlsx, .xls">
                </div>
            </div>

            <div class="stats">
                <div class="stat-card">
                    <div class="stat-icon" style="background: #DBEAFE; color: #1D4ED8;">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-value" id="total-students">0</div>
                        <div class="stat-label">学生总数</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon" style="background: #FCE7F3; color: #BE185D;">
                        <i class="fas fa-male"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-value" id="male-count">0</div>
                        <div class="stat-label">男生人数</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon" style="background: #D1FAE5; color: #047857;">
                        <i class="fas fa-female"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-value" id="female-count">0</div>
                        <div class="stat-label">女生人数</div>
                    </div>
                </div>

                <div class="stat-card">
                    <div class="stat-icon" style="background: #FEF3C7; color: #B45309;">
                        <i class="fas fa-chalkboard-teacher"></i>
                    </div>
                    <div class="stat-content">
                        <div class="stat-value" id="class-count">0</div>
                        <div class="stat-label">班级数量</div>
                    </div>
                </div>
            </div>
        </header>

        <!-- 表格区域 -->
        <div class="table-container">
            <div class="table-header">
                <h2 class="table-title">学生信息列表</h2>
                <div class="search-box">
                    <i class="fas fa-search"></i>
                    <input type="text" id="search-input" placeholder="搜索学生姓名或学号...">
                </div>
            </div>

            <div id="table-content">
                <div class="empty-state">
                    <i class="fas fa-file-excel"></i>
                    <h3>暂无学生数据</h3>
                    <p>请上传Excel文件以加载学生数据。文件应包含学生姓名、学号、班级、性别等信息。</p>
                </div>
            </div>
        </div>

        <!-- 页脚 -->
        <footer>
            <p>© 2023 学生管理系统 | 基于Excel数据的学生管理工具</p>
        </footer>
    </div>

    <script>
        // 模拟的Excel数据（在实际应用中，这里会从上传的Excel文件中读取）
        const mockData = [
            { id: "S2023001", name: "张三", class: "1", seat: "11", score: 92 },
            { id: "S2023002", name: "李四", class: "1", seat: "11", score: 85 },
            { id: "S2023003", name: "王芳", class: "1", seat: "12", score: 96 },
            { id: "S2023004", name: "刘洋", class: "2", seat: "11", score: 78 },
            { id: "S2023005", name: "陈婷婷", class: "2", seat: "12", score: 88 },
            { id: "S2023006", name: "赵敏", class: "2", seat: "12", score: 91 },
            { id: "S2023007", name: "孙伟", class: "3", seat: "11", score: 82 },
            { id: "S2023008", name: "周丽", class: "3", seat: "12", score: 95 },
            { id: "S2023009", name: "吴强", class: "3", seat: "11", score: 79 },
            { id: "S2023010", name: "郑小燕", class: "4", seat: "12", score: 89 },
            { id: "S2023011", name: "王磊", class: "4", seat: "11", score: 87 },
            { id: "S2023012", name: "冯娟", class: "4", seat: "12", score: 93 }
        ];

        // 当前展示的数据
        let currentData = [];

        // DOM元素
        const fileInput = document.getElementById('file-input');
        const classSelect = document.getElementById('class-select');
        const searchInput = document.getElementById('search-input');
        const tableContent = document.getElementById('table-content');
        const totalStudents = document.getElementById('total-students');
        const maleCount = document.getElementById('male-count');
        const femaleCount = document.getElementById('female-count');
        const classCount = document.getElementById('class-count');

        // 初始化页面
        document.addEventListener('DOMContentLoaded', function () {
            // 模拟上传数据后的效果
            setTimeout(() => {
                processData(mockData);
            }, 1000);
        });

        // 文件上传处理
        fileInput.addEventListener('change', function (e) {
            const file = e.target.files[0];
            if (!file) return;

            const reader = new FileReader();
            reader.onload = function (e) {
                const data = new Uint8Array(e.target.result);
                const workbook = XLSX.read(data, { type: 'array' });

                // 获取第一个工作表
                const worksheet = workbook.Sheets[workbook.SheetNames[0]];
                const jsonData = XLSX.utils.sheet_to_json(worksheet);

                // 处理数据
                processData(jsonData);
            };
            reader.readAsArrayBuffer(file);
        });

        // 处理数据并更新UI
        function processData(data) {
            currentData = data;

            // 更新统计信息
            updateStats(data);

            // 渲染表格
            renderTable(data);
        }

        // 更新统计信息
        function updateStats(data) {
            totalStudents.textContent = data.length;

            const male = data.filter(student => student.gender === '男').length;
            const female = data.filter(student => student.gender === '女').length;

            maleCount.textContent = male;
            femaleCount.textContent = female;

            // 计算班级数量
            const classes = new Set(data.map(student => student.class));
            classCount.textContent = classes.size;
        }

        // 渲染表格
        function renderTable(data) {
            if (data.length === 0) {
                tableContent.innerHTML = `
                    <div class="empty-state">
                        <i class="fas fa-user-slash"></i>
                        <h3>没有符合条件的学生</h3>
                        <p>请尝试更改筛选条件或搜索关键词</p>
                    </div>
                `;
                return;
            }

            // 创建表格
            let tableHTML = `
                <table>
                    <thead>
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>班级</th>
                            <th>性别</th>
                            <th>联系方式</th>
                            <th>综合成绩</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
            `;

            data.forEach(student => {
                tableHTML += `
                    <tr>
                        <td class="student-id">${student.id}</td>
                        <td>${student.name}</td>
                        <td><span class="class-badge class-${student.class}">高一(${student.class})班</span></td>
                        <td>${student.gender}</td>
                        <td>${student.phone || '未提供'}</td>
                        <td><span class="score">${student.score || '0'}</span></td>
                        <td>
                            <div class="actions">
                                <div class="action-btn" title="查看详情">
                                    <i class="fas fa-eye"></i>
                                </div>
                                <div class="action-btn" title="编辑">
                                    <i class="fas fa-edit"></i>
                                </div>
                                <div class="action-btn" title="删除">
                                    <i class="fas fa-trash-alt"></i>
                                </div>
                            </div>
                        </td>
                    </tr>
                `;
            });

            tableHTML += `
                    </tbody>
                </table>
            `;

            tableContent.innerHTML = tableHTML;
        }

        // 班级筛选
        classSelect.addEventListener('change', function () {
            filterData();
        });

        // 搜索功能
        searchInput.addEventListener('input', function () {
            filterData();
        });

        // 筛选数据
        function filterData() {
            const selectedClass = classSelect.value;
            const searchTerm = searchInput.value.toLowerCase();

            let filteredData = [...currentData];

            // 班级筛选
            if (selectedClass !== 'all') {
                filteredData = filteredData.filter(student => student.class === selectedClass);
            }

            // 搜索筛选
            if (searchTerm) {
                filteredData = filteredData.filter(student =>
                    student.name.toLowerCase().includes(searchTerm) ||
                    student.id.toLowerCase().includes(searchTerm)
                );
            }

            // 更新统计信息
            updateStats(filteredData);

            // 重新渲染表格
            renderTable(filteredData);
        }

        // 模拟文件上传功能
        document.querySelector('.file-upload-btn').addEventListener('click', function () {
            if (!fileInput.files.length) {
                fileInput.click();
            }
        });
    </script>
</body>

</html>